package com.yzy.service;

import com.yzy.demo.Progress;
import com.yzy.demo.ProgressList;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Service
public class CpuService {
    public ArrayList<Progress> myFCFS(String myName1,String myName2,String myName3,String myName4,String myName5,String myName6,String myName7,
                                      String myArriveTime1,String myArriveTime2,String myArriveTime3,String myArriveTime4,String myArriveTime5,String myArriveTime6,String myArriveTime7,
                                      String myRunTime1,String myRunTime2,String myRunTime3,String myRunTime4,String myRunTime5,String myRunTime6,String myRunTime7){

        ArrayList<Progress> myProgressList = new ArrayList<>();
        myProgressList.add(new Progress(myName1,Integer.parseInt(myArriveTime1),Integer.parseInt(myRunTime1)));
        myProgressList.add(new Progress(myName2,Integer.parseInt(myArriveTime2),Integer.parseInt(myRunTime2)));
        myProgressList.add(new Progress(myName3,Integer.parseInt(myArriveTime3),Integer.parseInt(myRunTime3)));
        myProgressList.add(new Progress(myName4,Integer.parseInt(myArriveTime4),Integer.parseInt(myRunTime4)));
        myProgressList.add(new Progress(myName5,Integer.parseInt(myArriveTime5),Integer.parseInt(myRunTime5)));
        myProgressList.add(new Progress(myName6,Integer.parseInt(myArriveTime6),Integer.parseInt(myRunTime6)));
        myProgressList.add(new Progress(myName7,Integer.parseInt(myArriveTime7),Integer.parseInt(myRunTime7)));

//        myProgressList.add(new Progress("P2",1,5));
//        myProgressList.add(new Progress("P3",2,2));
        for(Progress p:myProgressList) {
            p.finishTime = 0;
            p.totalTime = 0;
            p.weightTotalTime = 0;
        }
        com.yzy.demo.Service service =new com.yzy.demo.Service();
        service.FCFS(myProgressList);
        return myProgressList;
    }

    public ArrayList<Progress> mySJF(String myName1, String myName2, String myName3, String myName4, String myName5, String myName6, String myName7,
                                     String myArriveTime1, String myArriveTime2, String myArriveTime3, String myArriveTime4, String myArriveTime5, String myArriveTime6, String myArriveTime7,
                                     String myRunTime1, String myRunTime2, String myRunTime3, String myRunTime4, String myRunTime5, String myRunTime6, String myRunTime7) {
        ArrayList<Progress> myProgressList = new ArrayList<>();
        myProgressList.add(new Progress(myName1,Integer.parseInt(myArriveTime1),Integer.parseInt(myRunTime1)));
        myProgressList.add(new Progress(myName2,Integer.parseInt(myArriveTime2),Integer.parseInt(myRunTime2)));
        myProgressList.add(new Progress(myName3,Integer.parseInt(myArriveTime3),Integer.parseInt(myRunTime3)));
        myProgressList.add(new Progress(myName4,Integer.parseInt(myArriveTime4),Integer.parseInt(myRunTime4)));
        myProgressList.add(new Progress(myName5,Integer.parseInt(myArriveTime5),Integer.parseInt(myRunTime5)));
        myProgressList.add(new Progress(myName6,Integer.parseInt(myArriveTime6),Integer.parseInt(myRunTime6)));
        myProgressList.add(new Progress(myName7,Integer.parseInt(myArriveTime7),Integer.parseInt(myRunTime7)));

        for(Progress p:myProgressList) {
            p.finishTime = 0;
            p.totalTime = 0;
            p.weightTotalTime = 0;
        }
        com.yzy.demo.Service service =new com.yzy.demo.Service();
        service.SJF(myProgressList);
        return myProgressList;
    }
}
